/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "main_task.h"
#include "display_task.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
/* Definitions for mainAppTask */
osThreadId_t mainAppTaskHandle;
const osThreadAttr_t mainAppTask_attributes = {
  .name = "mainAppTask",
  .stack_size = 512 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for displayTask */
osThreadId_t displayTaskHandle;
const osThreadAttr_t displayTask_attributes = {
  .name = "displayTask",
  .stack_size = 512 * 4,
  .priority = (osPriority_t) osPriorityLow,
};
/* Definitions for MainAppMsg */
osMessageQueueId_t MainAppMsgHandle;
const osMessageQueueAttr_t MainAppMsg_attributes = {
  .name = "MainAppMsg"
};
/* Definitions for DisplayTaskMsg */
osMessageQueueId_t DisplayTaskMsgHandle;
const osMessageQueueAttr_t DisplayTaskMsg_attributes = {
  .name = "DisplayTaskMsg"
};

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void MainAppTask(void *argument);
void DisplayTask(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */
    MainAppMsgHandle = osMessageQueueNew (16, sizeof(uint16_t), &MainAppMsg_attributes);

    DisplayTaskMsgHandle = osMessageQueueNew (16, sizeof(uint16_t), &DisplayTaskMsg_attributes);

    mainAppTaskHandle = osThreadNew(MainAppTask, NULL, &mainAppTask_attributes);

    displayTaskHandle = osThreadNew(DisplayTask, NULL, &displayTask_attributes);

  /* USER CODE END Init */
/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/**
  * @}
  */

/**
  * @}
  */
}

/* USER CODE BEGIN Header_MainAppTask */
/**
  * @brief  Function implementing the mainAppTask thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_MainAppTask */
void MainAppTask(void *argument)
{
  /* USER CODE BEGIN MainAppTask */
    MainAppTaskEntrance();
    DBG("error: mainapp task delete\n");
    vTaskDelete(NULL);
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END MainAppTask */
}

/* USER CODE BEGIN Header_DisplayTask */
/**
* @brief Function implementing the displayTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_DisplayTask */
void DisplayTask(void *argument)
{
  /* USER CODE BEGIN DisplayTask */
    DisplayTaskEntrance();
    DBG("error: display task delete\n");
    vTaskDelete(NULL);
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END DisplayTask */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

osMessageQueueId_t GetMainMessageHandle(void)
{
    return MainAppMsgHandle;
}

osMessageQueueId_t GetDisplayMessageHandle(void)
{
    return DisplayTaskMsgHandle;
}

/* USER CODE END Application */

